package sweet.helper.model

/** A trait that provide saving and loading from a properties file using
 * reflections injections.
 */
trait Model extends ScalaReflection with Logger {
  import sweet.helper._
      
  def fromMap(props: scala.collection.Map[String, String]): Unit = {
    for((name,v) <- props){
      logger.debug("Invoking "+name+" setter with value "+v)
      val setter = setters(name)
      setter(v)
    }
  }
  def toMap: scala.collection.Map[String, String] = {    
    val props = SProperties()
    for((name,getter) <- getters){
      logger.debug("Invoking "+name+" getter")
      val v = getter()
      logger.debug("Value "+v)
      props(name) = v.toString
    }
    props.readOnly
  }
}

